package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.pojo.Order;
import com.itheima.pojo.OrderSetting;
import com.itheima.pojo.OrderSettingVO;
import com.itheima.service.OrderSettingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController("backendOrderSettingController")
@Slf4j
@RequestMapping("/ordersetting")
public class OrderSettingController {
    @Autowired
    OrderSettingService orderSettingService;
    @PostMapping("/editNumberByOrderDate")
    Result updateNumberByOrderDate(@RequestBody OrderSetting orderSetting){
        orderSettingService.updateNumberByOrderDate(orderSetting);
        return new Result(true,"预约设置成功");
    }
    @GetMapping("/getOrderSettingByMonth")
    Result getOrderSettingByMonth(String month){
        log.info("查询:{}月的预约数据", month);
        List<OrderSettingVO> list = orderSettingService.getOrderSettingByMonth(month);
        return new Result(true, MessageConstant.GET_ORDERSETTING_SUCCESS, list);
    }
    @PutMapping("/upload")
    Result uploadExcel(MultipartFile multipartFile){
        log.info("上传文件:{}", multipartFile.getName());
        orderSettingService.upload(multipartFile);
        return new Result(true,"预约设置成功");
    }

    @GetMapping("/download")
    String getFile(String filename, HttpServletResponse response){
        log.info("下载模板文件: {}", filename);
        orderSettingService.download(filename,response);
        return "文件下载";
    }

}
